﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Security;

namespace RXY_Mall.Admin.Authorize
{
    public class AuthorizeHelper
    {
        public static HttpCookie AddUserCookie(UserCookie userCookie, bool isRemember)
        {
            var serializer = new JavaScriptSerializer();
            var userData = serializer.Serialize(userCookie);

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
                name: userCookie.Token,
                issueDate: DateTime.Now,
                expiration: DateTime.Now.AddMinutes(60 * 6),
                isPersistent: isRemember,
                userData: userData,
                cookiePath: FormsAuthentication.FormsCookiePath);
            string encTicket = FormsAuthentication.Encrypt(ticket);

            return new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
        }

    }
}